define(function() {
	return function($compile, $scope) {
		require(
				[ "PDAppDir/properties", "AppPathDir/register/auditInfos/support",
						"PDUtilDir/util", "PDUtilDir/inputSelect", "PDUtilDir/fileupload/singleFileUpload", "PDUtilDir/validator", "Date",
						"DateCN", "css!DateCss" ],
				function(Properties, Support, Util, inputSelect, MFU, validator) {
					/* 查询 start */
					$scope.validator = validator;
					$scope.entity = {
						auditStatus: "D_AUDIT_STATUS_NO_PASS"
					};
					$scope.cache = {
						SERVER_URL: Properties.URL_FILE_SERVER_URL,
						isOk: false,
						isAudit: false,
						images: new Array()
					};
					
					$scope.auditSupport = {
						run : function() {
							$scope.entity = $.extend($scope.entity, {
								guideCardImageId: $scope.cache.image.guideCardImageId,
	                			guideCardImagePath: $scope.cache.image.guideCardImagePath
							});
							$.ajax({
			                    url : getServer() + "/flea/hclv/guide/submitGuideInfo.htmls",
			                    data : {
			                        'model' : JSON.stringify($scope.entity)
			                    },
			                    success : function(data) {
                                    if (data.status != 200) {
                                        return;
                                    }
			                    	$scope.cache.isAudit = true;
			                        Util.alert(data.message);
			                    }
							});
						}
					};
					MFU.init({
		                placeAt:"guideCardImage",
		                allowDelete:true,
		                allowMC:true,
		                onUploadSuccess:function(file){
//		                	$.each($scope.cache.images, function(index, row){
//		                    	if(row.key == file.name){
//		                    		row = $.extend(row, {
//		                    			resouceId: file.swordFileId,
//		                    			path: file.swordFilePath
//		                    		});
//		                    	}
//		                    });
		                	$scope.cache.image = $.extend($scope.cache.image, {
	                			guideCardImageId: file.swordFileId,
	                			guideCardImagePath: file.swordFilePath
                    		});
		                	$scope.cache.isOk = true;
		                	$scope.guideAuditForm.isOk.$setViewValue($scope.cache.isOk);
		                },
		                onDeleteSavedFile:function(file){
                            if(file == null) {
                                return;
                            }
                            $scope.cache.image = {};
                            $scope.guideAuditForm.isOk.$setViewValue($scope.cache.isOk);
                            $scope.$digest();
		                },
		                onFileQueued: function(/*files*/file){
                            if(ImageSuffix.indexOf(file.ext.toLowerCase()) < 0){
                                Util.alert(ImageSuffixNotSupport);
                                this.remove();
                                return;
                            }
                            var webUploader = this.webUploader;
                            webUploader.makeThumb( file, function( error, src ) {
                                if ( error ) {
                                    Util.alert('不能预览');
                                    return;
                                }
                                $scope.cache.image = {
                                    key: file.name,
                                    src: src
                                }
                                $scope.$digest();
                            }, 500, 300 );
		                	webUploader.upload();
		                }
		            });
					$.ajax({
						url : getServer() + "/flea/hclv/guide/getGuideInfoByUserId.htmls",
						success : function(data) {
							if(data.status == 200){
								$scope.entity = data.data;
								$scope.getCity($scope.entity.province);
								$scope.cache.image = {
									path: $scope.entity.guideCardImagePath
								}
							}
							$scope.getProvince();
							//未通过审核可以修改
							if($scope.entity.auditStatus != "D_AUDIT_STATUS_NO_PASS"){
								$scope.cache.isAudit = true;
							}
							$scope.$digest();
						}
					});
					$scope.getProvince = function() {
						$.ajax({
							url : getServer() + "/flea/hclv/getProvinces.htmls",
							success : function(data) {
								$scope.cache.provinces = data.data;
								// 初始化下拉框
								inputSelect.dropCache();
								inputSelect({
									id : "provinceName",
									key : {
										id : "dictCode",
										name : "dictName",
										data : "data",
									},
									data : $scope.cache.provinces,
									simpleData : true,
									// 启用文本搜索
									initData:[$scope.entity.province],
									searchAble : false,
									callback : function(id) {
										$scope.entity.province = id[0];
										$scope.guideAuditForm.province.$setViewValue($scope.entity.province);
										$scope.getCity($scope.entity.province);
									}
								});
							}
						});
					}
					$scope.getCity = function(id) {
						$.ajax({
							url : getServer() + "/flea/hclv/getCity.htmls",
							data : {
								'pcode' : id
							},
							success : function(data) {
								var citys = data.data;
								// 初始化下拉框
								inputSelect.dropCache();
								inputSelect({
									id : "cityName",
									key : {
										id : "dictCode",
										name : "dictName",
										data : "data",
									},
									data : citys,
									simpleData : true,
									// 启用文本搜索
									initData:[$scope.entity.city],
									searchAble : false,
									callback : function(id) {
										$scope.entity.city = id[0];
										$scope.guideAuditForm.city.$setViewValue($scope.entity.city);
									}
								});
							}
						});
					}
					$("#guideCardDueTime").datetimepicker({
						// 设置使用语言：cn是自定义的中文版本，还可以扩展其他语言版本
						language : "cn",
						// 输出格式化
						format : 'yyyy-mm-dd',
						// 直接选择‘今天’
						todayBtn : true,
						// 设置最精确的时间选择视图
						minView : 'month',
						// 高亮当天日期
						todayHighlight : true,
						// 选择完毕后自动关闭
						autoclose : true
					});
				})
	}
});